/**
 * bodyparser中间件
 * @author xiaoqiang <465633678@qq.com>
 * @created 2018/11/01 16:22:38
 */
const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const app = new Koa()
app.use(bodyParser())

app.use(async (ctx) => {
  /**
   * 判断路由地址是否是首页
   * 并且请求方式为get
   */
  if (ctx.url === '/' && ctx.method === 'GET') {
  ctx.body = `
      <html>
        <head>
          <title>标题</title>
        </head>
        <body>
          <form action="/" method="post">
            <div>
              用户名：
              <input value="" name="username" />
            </div>
            <div>
              密码：
              <input value="" name="password" />
            </div>
            <button type="submit">提交</button>
          </form>
        </body>
      </html>
    `
  } else if (ctx.url === '/' && ctx.method === 'POST') {
    ctx.body = ctx.request.body
  }
}).listen(9999)
console.log('服务启动于9999端口')